package com.unicampmaps;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

public class Venue {
	private int id;
	private String foursquare_venue_id;
	private int type;
	private String name;
	private String abbr;
	private String address;
	private float latitude;
	private float longitude;
	private String phone_number;
	private String site;
	private String image;

	private final int[] samples = {0, 
								   R.drawable.ic_hamburger_gray, R.drawable.ic_tablet_gray,  
								   R.drawable.ic_gear_gray, R.drawable.ic_book_gray, 
								   R.drawable.ic_bus_gray, R.drawable.ic_info_gray};
	
	public Venue(int id, String foursquare_venue_id, int type, String name, String abbr, String address,
			float latitude, float longitude, String phone_number, String site, String image) {
		super();
		this.id = id;
		this.foursquare_venue_id = foursquare_venue_id;
		this.type = type;
		this.name = name;
		this.abbr = abbr;
		this.address = address;
		this.latitude = latitude;
		this.longitude = longitude;
		this.phone_number = phone_number;
		this.site = site;
		this.image = image;
	}
	public int getId() {
		return id;
	}
	public String getFoursquare_venue_id() {
		return foursquare_venue_id;
	}
	public void setFoursquare_venue_id(String foursquare_venue_id) {
		this.foursquare_venue_id = foursquare_venue_id;
	}
	public int getType() {
		return type;
	}
	public String getName() {
		return name;
	}
	public String getAbbr() {
		return abbr;
	}
	public String getAddress() {
		return address;
	}
	public float getLatitude() {
		return latitude;
	}
	public float getLongitude() {
		return longitude;
	}
	public String getPhone_number() {
		return phone_number;
	}
	public String getSite() {
		return site;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setType(int type) {
		this.type = type;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setAbbr(String abbr) {
		this.abbr = abbr;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void setLatitude(float latitude) {
		this.latitude = latitude;
	}
	public void setLongitude(float longitude) {
		this.longitude = longitude;
	}
	public void setPhone_number(String phone_number) {
		this.phone_number = phone_number;
	}
	public void setSite(String site) {
		this.site = site;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	
	public int getImageResource() {
		return this.samples[this.type];
	}
	
	public static List<Venue> getVenues(ContentResolver contentResolver, int type) {
		List<Venue> venues = new ArrayList<Venue>();
		
		String[] projection = { 
			    VenueData.C_ID,
			    VenueData.C_FOURSQUARE_VENUE_ID,
			    VenueData.C_TYPE,
			    VenueData.C_NAME,
			    VenueData.C_ABBR,
			    VenueData.C_ADDRESS,
			    VenueData.C_LATITUDE, 
			    VenueData.C_LONGITUDE,
			    VenueData.C_PHONE_NUMBER, 
			    VenueData.C_SITE,
			    VenueData.C_IMAGE};
		
		
        //Busca por tipo de ponto de interesse
		Uri uri = VenueProvider.CONTENT_URI;
		Cursor cursor = contentResolver.query(uri, projection, VenueData.C_TYPE+ " = ?", new String[]{String.valueOf(type)}, null);
		
		if (cursor != null) {
			cursor.moveToFirst();
			
			for (int i = 0; i < cursor.getCount(); i++) {
				int id = cursor.getInt(cursor.getColumnIndexOrThrow(VenueData.C_ID));
				String fourquare_venue_id = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_FOURSQUARE_VENUE_ID));
				//int type = cursor.getInt(cursor.getColumnIndexOrThrow(VenueData.C_TYPE));
				String name = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_NAME));
				String abbr = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_ABBR));
				String address = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_ADDRESS));
				float latitude = cursor.getFloat(cursor.getColumnIndexOrThrow(VenueData.C_LATITUDE));
				float longitude = cursor.getFloat(cursor.getColumnIndexOrThrow(VenueData.C_LONGITUDE));
				String phone_number = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_PHONE_NUMBER));
				String site = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_SITE));
				String image = cursor.getString(cursor.getColumnIndexOrThrow(VenueData.C_IMAGE));
		        
				Venue v = new Venue(id, fourquare_venue_id, type, name, abbr, address, latitude, longitude, phone_number, site, image);
				
				venues.add(v);
		        
		        cursor.moveToNext();
			}
			
			cursor.close();
		}
		
		return venues;
	}
}
